
using Youz.Common.Entity;
using Youz.Common.Helper;
using Youz.CreditRepay.DAL;
using Youz.CreditRepay.Entity;
using System;
using System.Data;
using System.Data.SqlClient;

namespace Youz.CreditRepay.BLL
{
    /// <summary>
    /// Member_AssetHistory BLL Class
    /// </summary>
    public partial class Member_AssetHistoryBLL : BaseBLL
    {
        Member_AssetHistoryDAL dal;

        public Member_AssetHistoryBLL()
        {
            dal = new Member_AssetHistoryDAL();
            base.ModuleName = "Member_AssetHistory";
            base.MenuName = "Member_AssetHistory";
        }

        #region  成员方法
        ///// <summary>
        ///// 生成ID
        ///// </summary>
        ///// <returns></returns>
        //public Int64 GenerateID()
        //{
        //    return dal.GenerateID();
        //}
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Member_AssetHistory model)
        {
            var r = dal.Add(model);

            base.WriteOperationLog(OperationType.Add, r, Core.GetJsonByObjectHaveTime(model));

            return r;
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Member_AssetHistory model)
        {
            var r = dal.Update(model);

            base.WriteOperationLog(OperationType.Update, r, Core.GetJsonByObjectHaveTime(model));

            return r;
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(Int64 HistoryID)
        {
            var r = dal.Delete(HistoryID);

            base.WriteOperationLog(OperationType.Delete, r, HistoryID);

            return r;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Member_AssetHistory Get(Int64 HistoryID)
        {
            return dal.Get(HistoryID);
        }

        /// <summary>
        /// 得到一个JSON对象
        /// </summary>
        public string GetJson(Int64 HistoryID)
        {
            return Core.GetJsonByObject(Get(HistoryID));
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Gets(string sqlWhere)
        {
            return dal.Gets(sqlWhere);
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet Gets(int top, string sqlWhere, string filedOrder)
        {
            return dal.Gets(top, sqlWhere, filedOrder);
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string sqlWhere)
        {
            return dal.GetRecordCount(sqlWhere);
        }

        /// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable Gets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            return dal.Gets(sqlWhere, pageindex, pagesize, out total, cmdParms);
        }

        public DataTable Gets(int top, string showColumn, string sqlWhere, params SqlParameter[] cmdParms)
        {
            return dal.Gets(top, showColumn, sqlWhere, cmdParms);
        }

        /// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable BillGets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            return dal.BillGets(sqlWhere, pageindex, pagesize, out total, cmdParms);
        }

        /// <summary>
        /// 手续费佣金明细
        /// </summary>
        /// <returns></returns>
        public DataTable GetsByTradeFeeAward()
        {
            var where = " AssetType='TradeFeeAward' and MemberAccount=@MemberAccount";
            var memberAccount = WebHelper.Post("MemberAccount");
            var lastID = WebHelper.Post<int>("LastID");
            var firstID = WebHelper.Post<int>("FirstID");
            SqlParameter[] cmdParms = {
                                 new SqlParameter("@MemberAccount", memberAccount),
                                 new SqlParameter("@FirstID", firstID),
                                 new SqlParameter("@LastID", lastID)
                             };

            if (firstID > 0)
            {
                where += " and HistoryID > @FirstID";
            }
            else if (lastID > 0)
            {
                where += " and HistoryID < @LastID";
            }

            return Gets(10, "HistoryID,ChangeBalance,CreateTime", where, cmdParms);
        }
        #endregion  成员方法

        /// <summary>
        ///  手续费佣金统计
        /// </summary>
        /// <returns></returns>
        public DataRow GetTradeFeeAwardStat(string memberAccount)
        {
            return dal.GetTradeFeeAwardStat(memberAccount);
        }
    }
}


